from rclpy.node import Node
from std_msgs.msg import String
# from faker import Faker
import datetime


# fake = Faker('zh_CN')
class SimpleTopicPub(Node):
    def __init__(self, name: str):
        super().__init__(name)
        self.publisher_ = self.create_publisher(String, 'simple_topic_message', 10)
        self.timer = self.create_timer(1, self.callback)

    def callback(self):
        current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]  # 精确到毫秒
        # 随机生成一句话
        random_sentence = '1234567890'
        # 组装成一个字符串
        result = f"当前时间: {current_time}, 随机语句: {random_sentence}"
        msg = String()
        msg.data = result
        self.publisher_.publish(msg)
        self.get_logger().info(result)

